﻿@using Smarly.Bussines.Model
@model List<BookTree>

@if (Model == null)
{
	return;
}

@foreach (var ch in Model)
{
	List<BookTree> children = ch.Children != null ? ch.Children.Where(x => x.IsHead).ToList() : new List<BookTree>();
	bool hasChild = children.Count > 0;

	var containChapter = ((List<long>) ViewBag.CurrentIds).Any(x => x == ch.Id);
	var currentChapter = ch.Id == ViewBag.ModelId;
	
	<li class="@Html.Raw(currentChapter ? "current" : string.Empty) @Html.Raw(!hasChild ? "no-child" : string.Empty)"  >
		@if (hasChild)
		{
			<input type="checkbox" @(containChapter ? "checked" : string.Empty)/><span class="have-child @Html.Raw(currentChapter ? "bold" : string.Empty)"><a href="@ch.Url" class="@(ch.Published ? "bgg" : "bgr")">@ch.Text</a></span>
			<ul>
				@Html.Partial("_TextTocPartial", children)
			</ul>
		}
		else
		{
			<span class="@Html.Raw(currentChapter ? "bold" : string.Empty)"><a href="@ch.Url" class="@(ch.Published ? "bgg" : "bgr")">@ch.Text</a></span>
		}
	</li>
}